import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Objects;

public class Demo3 {
    public static void main(String[] args) {
        //自定义的一个有序的集合
        List<Integer> asList = Arrays.asList(1, 2, 3, 4, 5, 6);// {1,2,3,4,5,6}

        //打乱集合中元素的顺序
        //Collections.shuffle(asList);

        //交换集合中指定下标的元素
        //Collections.swap(asList, 0, 5);

        Collections.replaceAll(asList, 1, 111);
        //输出集合中的元素
        //asList.forEach(System.out::print);

        //将4个Item的对象插入到集合
        List<Item> items = Arrays.asList(
                new Item(1),
                new Item(2),
                new Item(3),
                new Item(4)
        );
        Collections.replaceAll(items, new Item(1), new Item(111));

        System.out.println("----------------");
        for (Item item : items) {
            System.out.print(item.i);
        }
    }

    static class Item{
        int i;

        public Item(int i) {
            this.i = i;
        }

        //alt + insert

        @Override
        public boolean equals(Object o) {
            if (this == o) return true;
            if (o == null || getClass() != o.getClass()) return false;
            Item item = (Item) o;
            return i == item.i;
        }

        @Override
        public int hashCode() {
            return Objects.hash(i);
        }
    }
}
